# cors跨域问题测试
'''
from rest_framework.views import APIView
from utils.exception import CommonResponse


class TestView(APIView):
    def get(self, request, *args, **kwargs):
        # 1 / 0
        return CommonResponse()


class CorsText(APIView):
    """
    def options(self, request, *args, **kwargs):
        print('request.method:', request.method)
        print("options 非简单请求")
        return CommonResponse(headers={'Access-Control-Request-Headers': 'Content-Type'})

    def get(self, request, *args, **kwargs):
        print("get 简单请求 或者 非简单请求")
        return CommonResponse(headers={'Access-Control-Allow-Origin': 'http://127.0.0.1:8041'})

    def post(self, request, *args, **kwargs):
        print("post 简单请求 或者 非简单请求")
        return CommonResponse(headers={'Access-Control-Allow-Origin': 'http://127.0.0.1:8041'})
    """
    def options(self, request, *args, **kwargs):
        print('request.method:', request.method)
        print("options 非简单请求")
        return CommonResponse()

    def get(self, request, *args, **kwargs):
        print("get 简单请求 或者 非简单请求")
        return CommonResponse()

    def post(self, request, *args, **kwargs):
        print("post 简单请求 或者 非简单请求")
        return CommonResponse()


from django.http import HttpResponse
from django.views.decorators.csrf import csrf_exempt


@csrf_exempt
def cors(request):
    """
    print('request.method:', request.method)
    obj = HttpResponse('ok')
    if request.method == 'OPTIONS':
        obj['Access-Control-Allow-Headers'] = 'Content-Type'
        obj['Access-Control-Allow-Methods'] = 'Content-Type'
    # obj['Access-Control-Allow-Origin'] = 'http://127.0.0.1:8041'
    obj['Access-Control-Allow-Origin'] = '*'
    return obj
    """
    return HttpResponse('ok')

# 这里的挎包导入就问题了:
"""
RuntimeError: Model class luffyapi.apps.user.models.User doesn't declare an explicit app_label and isn't in an application in INSTALLED_APPS.

from luffyapi.apps.user.models import User
"""
'''

from rest_framework.generics import ListAPIView
from rest_framework.viewsets import ViewSetMixin

from . import models
from django.conf import settings
from . import serializer


class BannerView(ViewSetMixin, ListAPIView):
    queryset = models.Banner.objects.filter(is_delete=False, is_show=True).order_by('display_order')[:settings.BANNER_COUNTER]
    serializer_class = serializer.BannerModelSerializer
